package com.aishua.andpaydemo.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.aishua.andpaydemo.R;

/**
 * Created by aishua on 2018/5/16.
 */

public class Extensionarea1Adapter  extends RecyclerView.Adapter<Extensionarea1Adapter.MyDeviceViewHoler> {

    private static final String TAG = "HomeHotAdapter-";
    private Context mContext;
    private String[] hotname;
    private String[] hotbg1;
    private Drawable[] hotname1bg;
    public Extensionarea1Adapter(Context mContext, String[] hotname,String[] hotbg1,Drawable[] hotname1bg){

        this.mContext = mContext;
        this.hotname = hotname;
        this.hotbg1 = hotbg1;
        this.hotname1bg = hotname1bg;
    }
    @Override
    public Extensionarea1Adapter.MyDeviceViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = View.inflate(mContext, R.layout.item_extensionarea1,null);
        Extensionarea1Adapter.MyDeviceViewHoler holder =new Extensionarea1Adapter.MyDeviceViewHoler(view);
        return holder;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onBindViewHolder(Extensionarea1Adapter.MyDeviceViewHoler holder, final int position) {

        holder.displayView(position);
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                onRecycleViewClickListener.onRecycleViewClick(position);
//            }
//        });

    }

    @Override
    public int getItemCount() {

        return hotname.length;
    }


    public class MyDeviceViewHoler extends RecyclerView.ViewHolder {

        private ImageView img_extension;
        private TextView tv_xuanchuna;
        private TextView tv_xuanchunafu;

        public MyDeviceViewHoler(View itemView) {
            super(itemView);

            img_extension = itemView.findViewById(R.id.img_extension);
            tv_xuanchuna =itemView.findViewById(R.id.tv_xuanchuna);
            tv_xuanchunafu =itemView.findViewById(R.id.tv_xuanchuafu);
        }

        @RequiresApi(api = Build.VERSION_CODES.M)
        public void displayView(int position) {

            img_extension.setBackground(hotname1bg[position]);
            tv_xuanchuna.setText(hotname[position]);
            tv_xuanchunafu.setText(hotbg1[position]);
        }

    }
    public void setonRecycleViewClickListener(HomeHotAdapter.onRecycleViewClickListener onRccycleViewLongClickListener){
        this.onRecycleViewClickListener =onRccycleViewLongClickListener;
    }
    private HomeHotAdapter.onRecycleViewClickListener onRecycleViewClickListener;

    public interface onRecycleViewClickListener{

        public void onRecycleViewClick(int position);

    }
}
